package com.gaoyi.basemodule.basedialog;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.view.ViewGroup;

import com.gaoyi.basemodule.R;
import com.gaoyi.basemodule.databinding.DialogToastBinding;


public class ToastDialog extends BaseFragmentDialog<DialogToastBinding> {

    private String msg;
    private int resId;
    AnimationDrawable mAnimationDrawable;

    public ToastDialog(Context context) {
        super(context);
    }

    public ToastDialog(Context context, DialogInterface.OnKeyListener onKeyListener) {
        super(context, onKeyListener);
    }

    public ToastDialog setIco(int resId) {
        this.resId = resId;
        return this;
    }

    public ToastDialog setMessage(String msg) {
        this.msg = msg;
        return this;
    }

    @Override
    public void initView() {
        mBinding.tvMsg.setText(msg);
        if (resId > 0) {
            mBinding.ivIco.setImageResource(resId);
            if (resId == R.drawable.ic_loading) {
                mAnimationDrawable = (AnimationDrawable) mBinding.ivIco.getDrawable();
                mBinding.ivIco.post(() -> mAnimationDrawable.start());
            }
        } else {
            mBinding.ivIco.setVisibility(View.GONE);
        }
    }

    @Override
    protected DialogToastBinding getViewBinding() {
        return DialogToastBinding.inflate(getLayoutInflater());
    }

    @Override
    protected String getShowTag() {
        return CENTER;
    }

    @Override
    protected int getWidth() {
        return ViewGroup.LayoutParams.WRAP_CONTENT;
    }
}
